﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
using DBSystem.BussinesEntities;

namespace DBSystem.Repository.Mapping
{
    public class UsuarioMap:EntityTypeConfiguration<Usuario>
    {
        public UsuarioMap()
        {
            //key
            this.HasKey(u => u.Id);

            //properties
            this.Property(u => u.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(u => u.Nombres)
                .HasMaxLength(200)
                .IsRequired();

            this.ToTable("Usuario");

            this.HasMany(u => u.Preferencias)
                .WithMany(p=>p.Usuarios)
                .Map(t => {
                    t.ToTable("PreferenciasUsuario");
                    t.MapRightKey("PreferenciaId");
                    t.MapLeftKey("UsuarioId");
                });


        }
    }
}